#include "service_view_impl.h"
void ServiceViewImpl::menuSec(void)
{
	vector<string> str;
	str.push_back("增加部门");
	str.push_back("删除部门");
	str.push_back("部门列表");
	str.push_back("增加员工");
	str.push_back("删除员工");
	str.push_back("修改员工");
	str.push_back("员工列表");
	str.push_back("全体员工名单");
	str.push_back("退出");
	int cmd=-1;
	while(cmd!=8)
	{
		clear_screen();
		cmd = -1;
		switch(cmd = get_cmd(str))
		{
			case 0:addDept(); break;
			case 1:delDept(); break;
			case 2:listDept(); break;
			case 3:addEmp(); break;
			case 4:delEmp(); break;
			case 5:modEmp(); break;
			case 6:listEmp(); break;
			case 7:listAllEmp(); break;
			default:break;
		}
	}
}
void ServiceViewImpl::addDept(void)
{
	//SrcCtrlImpl* sci = new SrcCtrlImpl;
	//srcCtrl = new ServiceCtrlImpl();
	Department dpm;
	srcCtrl->addDept(dpm);
}
void ServiceViewImpl::delDept(void)
{
	//SrcCtrlImpl* sci = new SrcCtrlImpl;
	//srcCtrl = new ServiceCtrlImpl();

	cout << "请输入要删除的部门id:";
	int id=0;
	cin.clear();
	cin >> id;
	srcCtrl->delDept(id);
}
void ServiceViewImpl::listDept(void)
{
	//SrcCtrlImpl* sci = new SrcCtrlImpl;
	//srcCtrl = new ServiceCtrlImpl();
	int num = srcCtrl->listDept().size();
	for(int i=0;i<num;i++)
	{
		cout << "部门编号:" << srcCtrl->listDept()[i].getId() << " " << "部门名称:" << srcCtrl->listDept()[i].getName() << " " << "部门员工数量:" << srcCtrl->listDept()[i].getNum() << endl;
	}
	anykey_continue();
}
void ServiceViewImpl::addEmp(void)
{
	//SrcCtrlImpl* sci = new SrcCtrlImpl;
	//srcCtrl = new ServiceCtrlImpl();
	cin.clear();
	cout << "请输入要添加的员工所属部门id:";
	int id=0;
	cin >> id;
	Employee emp;
	srcCtrl->addEmp(id,emp);
}
void ServiceViewImpl::delEmp(void)
{
	//SrcCtrlImpl* sci = new SrcCtrlImpl;
	//srcCtrl = new ServiceCtrlImpl();
	cin.clear();
	cout << "请输入要删除的员工所属部门id:";
	int id=0;
	cin >> id;
	srcCtrl->delEmp(id);
}
void ServiceViewImpl::modEmp(void)
{
	//SrcCtrlImpl* sci = new SrcCtrlImpl;
	//srcCtrl = new ServiceCtrlImpl();
	cin.clear();
	cout << "请输入要修改的员工所属部门id:";
	int id=0;
	cin >> id;
	Employee emp;
	srcCtrl->modEmp(id,emp);
}
void ServiceViewImpl::listEmp(void)
{
	//SrcCtrlImpl* sci = new SrcCtrlImpl;
	//srcCtrl = new ServiceCtrlImpl();
	cin.clear();
	cout << "请输入要察看的员工所属部门id:";
	int id=0;
	cin >> id;
	for(int i=0;i<srcCtrl->listDept().size();i++)
	{
		if(id == srcCtrl->listDept()[i].getId())
		{
			for(int j=0;j<srcCtrl->listDept()[i].getNum();j++)
			{
		cout << "员工编号:" << srcCtrl->listDept()[i].empArr[j].getId() << " " << "员工名称:" << srcCtrl->listDept()[i].empArr[j].getName() << " " << "员工性别:" << translate(srcCtrl->listDept()[i].empArr[j].getSex()) << " " << "员工年龄:" << srcCtrl->listDept()[i].empArr[j].getAge() << endl;
			} 
		}
	}
	anykey_continue();
}
void ServiceViewImpl::listAllEmp(void)
{
	//SrcCtrlImpl* sci = new SrcCtrlImpl;
	//srcCtrl = new ServiceCtrlImpl();
	for(int i=0;i<srcCtrl->listDept().size();i++)
	{
		for(int j=0;j<srcCtrl->listDept()[i].getNum();j++)
		{
			cout << "员工编号:" << srcCtrl->listDept()[i].empArr[j].getId() << " " << "员工名称:" << srcCtrl->listDept()[i].empArr[j].getName() << " " << "员工性别:" << translate(srcCtrl->listDept()[i].empArr[j].getSex()) << " " << "员工年龄:" << srcCtrl->listDept()[i].empArr[j].getAge() << endl; 
		}
	}
	anykey_continue();
}
